import Vue from 'vue'
import Router from 'vue-router'
import home from '@/components/home' //首页
import checkRoom from '@/components/checkRoom' //查询房间
import addhome from '@/components/addhome' //代理查询
import recharge from '@/components/recharge' //代理充值
import gamehome from '@/components/gamehome' //查询玩家
import gamecongzhi from '@/components/gamecongzhi' //查询玩家
import password from '@/components/password' //修改密码
import addagency from '@/components/addagency' //新增代理

import particulars from '@/components/particulars ' //查询代理详情
import logo from '@/components/logo' //登陆
import record from "@/components/record/record"; //代理记录
import gameRecord from "@/components/record/gameRecord"; //玩家记录

import down from "@/components/record/down"; //代理详情记录

import downRecord from "@/components/record/downRecord"; //玩家详情记录

import myset from "@/components/myset"; //我的信息

import agentback from "@/components/Back/agentback"; //代理充值回退
import gameback from "@/components/Back/gameback"; //玩家充值回退


import homes from "@/components/homes"; //代理商页面
import person from "@/components/person"; //代理商个人信息
import checkRoomww from "@/components/checkRoomww"; //代理商查询房间
import gamehomeww from "@/components/gamehomeww"; //代理商查询玩家
import gamecongzhiww from "@/components/gamecongzhiww"; //代理商玩家充值
import gameRecordww from "@/components/record/gameRecordww"; //代理商玩家充值记录
import passwordww from "@/components/passwordww"; //代理商修改密码

Vue.use(Router)

const router = new Router({
    routes: [{
            path: '/',
            name: '首页',
            component: home,
            meta: {
                requiresAuth: true
            }
        },
        { path: '/logo', name: '登陆', component: logo }, //登陆
        {
            path: '/checkRoom',
            name: '查询房间',
            component: checkRoom,
            meta: {
                requiresAuth: true
            }
        },
        {
            path: '/addhome',
            name: '代理查询',
            component: addhome,
            meta: {
                requiresAuth: true
            }
        },
        {
            path: '/recharge',
            name: '代理充值',
            component: recharge,
            meta: {
                requiresAuth: true
            }
        },
        {
            path: '/gamehome',
            name: '玩家查询',
            component: gamehome,
            meta: {
                requiresAuth: true
            }
        },
        {
            path: '/gamecongzhi',
            name: '玩家充值',
            component: gamecongzhi,
            meta: {
                requiresAuth: true
            }
        },
        {
            path: '/password',
            name: '修改密码',
            component: password,
            meta: {
                requiresAuth: true
            }
        },
        {
            path: '/addagency',
            name: '新增代理',
            component: addagency,
            meta: {
                requiresAuth: true
            }
        },
        {
            path: '/particulars/:id',
            name: '代理详情',
            component: particulars,
            meta: {
                requiresAuth: true
            }
        },
        {
            path: '/record',
            name: '代理记录',
            component: record,
            meta: {
                requiresAuth: true
            }
        },
        {
            path: '/gameRecord',
            name: '玩家记录',
            component: gameRecord,
            meta: {
                requiresAuth: true
            }
        },
        {
            path: '/down/:ids',
            name: '代理记录详情',
            component: down,
            meta: {
                requiresAuth: true
            }
        },
        {
            path: '/downRecord/:ids',
            name: '玩家记录详情',
            component: downRecord,
            meta: {
                requiresAuth: true
            }
        },
        {
            path: '/homes',
            name: '二级页面',
            component: homes,
            meta: {
                requiresAuth: true
            }
        },
        {
            path: '/myset',
            name: '我的信息',
            component: myset,
            meta: {
                requiresAuth: true
            }
        },
        {
            path: '/agentback',
            name: '代理充值回退',
            component: agentback,
            meta: {
                requiresAuth: true
            }
        },
        {
            path: '/gameback',
            name: '玩家充值回退',
            component: gameback,
            meta: {
                requiresAuth: true
            }
        },
        {
            path: '/person',
            name: '代理商个人信息',
            component: person,
            meta: {
                requiresAuth: true
            }
        },
        {
            path: '/checkRoomww',
            name: '代理商查询房间',
            component: checkRoomww,
            meta: {
                requiresAuth: true
            }
        },
        {
            path: '/gamehomeww',
            name: '代理商玩家查询',
            component: gamehomeww,
            meta: {
                requiresAuth: true
            }
        },
        {
            path: '/gamecongzhiww',
            name: '代理商玩家充值',
            component: gamecongzhiww,
            meta: {
                requiresAuth: true
            }
        },
        {
            path: '/gameRecordww',
            name: '代理商玩家充值记录',
            component: gameRecordww,
            meta: {
                requiresAuth: true
            }
        },
        {
            path: '/passwordww',
            name: '代理商修改密码',
            component: passwordww,
            meta: {
                requiresAuth: true
            }
        }

    ]
})

router.beforeEach((to, from, next) => {
    if (to.matched.some(record => record.meta.requiresAuth)) {
        if (!sessionStorage.getItem('token')) {
            next({
                path: '/logo',
                query: {
                    redirect: to.fullPath
                }
            })
        } else {
            next()
        }
    } else {
        next()
    }
})

export default router